require.config({
　　　paths: {
　　　　　"jquery" : "../vendors/jquery/dist/jquery.min",
　　　　　"sematic": "../vendors/semantic/dist/semantic.min",
          "slimscroll": "../module/component/slimscroll",
          "unslider": "../module/component/unslider.min"
　　　},
      shim: {
　　　　　'slimscroll': {
　　　　　　　　deps: ['jquery'],
　　　　　　　　exports: 'jQuery.fn.slimScroll'
　　　　　}
      }
});
require(['jquery','sematic','slimscroll','unslider'], function($,sematic,slimscroll,unslider){
   
    var $dropdown = $('.ui.dropdown').not('.publish-option'),
	    $publish = $('.ui.dropdown.publish-option'),
		$li       = $('.filter-list li a'),
        $pic      = $('.two-dimension')
        // $order    = $('.site-search .item')

    // index
    var slidey = $('.banner').unslider({
        dots: true
    });
    // have bug
    $('.unslider-arrow').click(function() {
        var fn = this.className.split(' ')[1];
            slidey.data('unslider')[fn]();
    });

    var backTop = $('.back-top');
    $('.back-top').on('click', function(){

        // firefox(html) an chrome(body) 
        $('body,html').animate({scrollTop: '0px'},300);
    })
    function scrollListen(){

       var top = $(window).scrollTop();
       $pic.css('top', top +'px');

       if(top > 242){
            backTop.addClass('on');
       }
       else
       {
            backTop.removeClass('on');
       }
    }
    $(window).on('scroll', function(){
        scrollListen();
    })  

	$dropdown
    .dropdown();
    
    // filter
    function filterFactors(li){
    	li.parent().addClass('active');
    	li.parent().siblings().removeClass('active');
    }
   
    $li.on('click.site',function(){
    	filterFactors($(this));
    })

    setTimeout(function(){
        $('.list-check__tip').removeClass('on');
    }, 3000);
   
    // slide
    var oDiv= $('#playimages');
    
    var oDivSmall= $('.small_pic');
    var oUlSmall= $('.small_pic ul');
    var aLiSmall= $('.small_pic li');
    var arrow_left = $('.arrow_left');
    var arrow_right = $('.arrow_right');
    
    var oUlBig= $('.big_pic');
    var aLiBig= $('.big_pic li');
    
    var nowZIndex=2;
    
    var now=0;
    
    aLiSmall.each(function(index){

        aLiSmall.eq(index).data('index', index);
        aLiSmall.eq(index).on('click', function(){

            if($(this).data('index') == now) return;
            
            now = $(this).data('index')
            tab();
        })
    })
    
    arrow_left.on('click' , function(){
    	now--;
    	if(now==-1)
    	{
    		now=aLiSmall.length-1;
    	}
    	
    	tab();
    })
    
    arrow_right.on('click', function(){
    	now++;
    	if(now==aLiSmall.length)
    	{
    		now=0;
    	}
    	
    	tab();
    })
    function tab()
    {
    	aLiBig.animate({ 'opacity': 0} ,'fast')
        aLiBig.eq(now).animate({ 'opacity': 1} ,'fast')
        
        aLiSmall.css('opacity', 0.6)
        aLiSmall.eq(now).css('opacity', 1)
        
        aLiBig.eq(now).css('opacity', 0)
        aLiBig.eq(now).animate({'opacity': 1} ,'fast')
        
        if(now==0)
        {
            oUlSmall.animate({'left': 0});
        }
        else
        {
            var width = aLiSmall.eq(0).width() + 12;
            oUlSmall.animate({'left': -width} ,'fast');
        }
    }

    var timer = setInterval(function(){
    	arrow_right.trigger('click')
    }, 9000);
    
    oDiv.on('mouseover', function(){
    	clearInterval(timer);
    })
    oDiv.on('mouseout', function(){
    	timer = setInterval(function(){
    		arrow_right.trigger('click')
    	}, 9000);
    })

    // publish
    var data = {
        community: '',
        userMobile: '',
        userName: '',
        roomNum: '',
        hallNum: '',
        toiletNum: ''

    }
    function verifyNull(){
        var tag = true;
        $('.publish-verify').each(function(){
            if($(this).val() ==''){
                $(this).css('border-color','#FF4354');
                tag = false;
            }
        })
        $('.publish-option option:selected').each(function(index){
            if($(this).val() ==''){
               $('.publish-option.selection').eq(index).css('border-color','#FF4354');
               tag = false;
            }
        })

        if(tag){
            $('.publish-verify').each(function(){
                data[$(this).data('name')] = $(this).val();
            })
            $('.publish-option option:selected').each(function(index){
                data[$('select').eq(index).data('name')] = $(this).val();
            })
           
            data[$('.expect-rent').data('name')] = $('.expect-rent').val();
            
            $.post('/landlord/publish?from=pc',data,function(data){
                if(data.code == 0){
                    modal();
                }
                else
                {
                    var img_url = $('.post-img').data('url');
                    $('.post-img').attr('src',img_url);
                    modal();
                }
            })
        }
        
    }
    function inputChange(){  
        $(this).css('border-color','rgba(0,0,0,.15)');  
    }
    var btn = $('.punlish-submit');
    var vfy = $('.publish-verify');
    btn.on('click', verifyNull);
    vfy.on('input propertychange', inputChange);

    $publish.dropdown({
        onChange: function(value, text, $choice){
            $('.publish-option option:selected').each(function(index){
                if($(this).val() !=''){
                    $('.publish-option.selection').eq(index).css('border-color','rgba(0,0,0,0.15)');
                }
            })
        }
    });
    
    // modal
    
        var $a = $('.common');
        var $bg = $('.modal-bg');
        var $inner = $('.modal-inner');
        var action = {
            'modal': modal,
            'removeModal': removeModal
        }
        
        function modal(){
            $bg.addClass('on');
            $inner.addClass('on');
        }
        function removeModal(){
            $bg.removeClass('on');
            $inner.removeClass('on');
        }
        $a.on('click', function(){
            action[$(this).data('action')]();
        })

    
    

})
